Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/clang tidy cleanup #1340

Merged
merged 15 commits into from
Sep 9, 2019
Merged

Conversation

SteveBronder
Copy link
Collaborator

Edit: Something weird is going on with the Jenkinsbot so I move the branch over to the main repo

Summary

Running clang-tidy with the checks below. This refactor is only aesthetic and does not change how any of the code is executed.

readability-braces-around-statements:

  • Adds braces around conditionals and ifs

modernize-use-using:
everywhere clang-tidy can replace a typedef with a using it will aka
typedef double A; becomes using A = double;

modernize-use-nullptr:
using nullptr instead of NULL

The original PR also had a cleanup to return a braced init list but after looking at the I didn't like it

Tests

refactor is only aesthetic so no new tests

Checklist

  • Math issue Update internals to use more modern c++ #1308

  • Copyright holder: Steve Bronder

    The copyright holder is typically you or your assignee, such as a university or company. By submitting this pull request, the copyright holder is agreeing to the license the submitted work under the following licenses:
    - Code: BSD 3-clause (https://opensource.org/licenses/BSD-3-Clause)
    - Documentation: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

  • the basic tests are passing

    • unit tests pass (to run, use: ./runTests.py test/unit)
    • header checks pass, (make test-headers)
    • docs build, (make doxygen)
    • code passes the built in C++ standards checks (make cpplint)
  • the code is written in idiomatic C++ and changes are documented in the doxygen

  • the new changes are tested

@stan-buildbot
Copy link
Contributor

(stat_comp_benchmarks/benchmarks/gp_pois_regr/gp_pois_regr.stan, 1.0)
(stat_comp_benchmarks/benchmarks/low_dim_corr_gauss/low_dim_corr_gauss.stan, 0.99)
(stat_comp_benchmarks/benchmarks/irt_2pl/irt_2pl.stan, 1.0)
(stat_comp_benchmarks/benchmarks/pkpd/one_comp_mm_elim_abs.stan, 0.99)
(stat_comp_benchmarks/benchmarks/eight_schools/eight_schools.stan, 1.01)
(stat_comp_benchmarks/benchmarks/gp_regr/gp_regr.stan, 0.99)
(stat_comp_benchmarks/benchmarks/arK/arK.stan, 1.0)
(performance.compilation, 1.02)
(stat_comp_benchmarks/benchmarks/low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan, 1.01)
(stat_comp_benchmarks/benchmarks/low_dim_gauss_mix/low_dim_gauss_mix.stan, 1.0)
(stat_comp_benchmarks/benchmarks/sir/sir.stan, 0.98)
(stat_comp_benchmarks/benchmarks/pkpd/sim_one_comp_mm_elim_abs.stan, 1.01)
(stat_comp_benchmarks/benchmarks/garch/garch.stan, 1.01)
(stat_comp_benchmarks/benchmarks/gp_regr/gen_gp_data.stan, 1.0)
(stat_comp_benchmarks/benchmarks/arma/arma.stan, 0.99)
Result: 0.99978557888
Commit hash: 3e9d7fe

Copy link
Member

@rok-cesnovar rok-cesnovar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, the changes for braces are all fine.

There are a few files where we are changing some typedefs to using but some are left as typedefs. For consistency I think we should change the rest to using also. No need to change all the typedefs, I just feel that mixing both in the same file should be avoided.

@@ -10,18 +10,18 @@ namespace math {

typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>::Index size_type;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this one manually so its consistent?

@@ -10,18 +10,18 @@ namespace math {

typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>::Index size_type;

typedef Eigen::Matrix<fvar<double>, Eigen::Dynamic, Eigen::Dynamic> matrix_fd;
using matrix_fd = Eigen::Matrix<fvar<double>, Eigen::Dynamic, Eigen::Dynamic>;

typedef Eigen::Matrix<fvar<fvar<double> >, Eigen::Dynamic, Eigen::Dynamic>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one too.

@@ -9,18 +9,18 @@
namespace stan {
namespace math {

typedef Eigen::Matrix<fvar<var>, Eigen::Dynamic, Eigen::Dynamic> matrix_fv;
using matrix_fv = Eigen::Matrix<fvar<var>, Eigen::Dynamic, Eigen::Dynamic>;

typedef Eigen::Matrix<fvar<fvar<var> >, Eigen::Dynamic, Eigen::Dynamic>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency please convert this one to using also.

@@ -28,7 +28,7 @@ namespace math {
*/
template <typename F, typename T1, typename T2, typename T_t0, typename T_ts>
struct coupled_ode_observer {
typedef return_type_t<T1, T2, T_t0, T_ts> return_t;
using return_t = return_type_t<T1, T2, T_t0, T_ts>;

typedef operands_and_partials<std::vector<T1>, std::vector<T2>, T_t0, T_ts>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just going to leave "using" for further comments where we can manually replace typdef.

const T_theta& theta,
const std::vector<Eigen::Matrix<T_lam, R, C> >& lambda) {
const std::vector<Eigen::Matrix<T_lam, R, C>>& lambda) {
static const char* function = "log_mix";
typedef typename stan::partials_return_type<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using?

@@ -24,8 +24,9 @@ return_type_t<T_y, T_loc, T_scale, T_inv_scale> exp_mod_normal_lpdf(
typedef partials_return_type_t<T_y, T_loc, T_scale, T_inv_scale>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using line 23

@@ -21,8 +21,9 @@ return_type_t<T_y, T_loc, T_scale, T_shape> pareto_type_2_cdf(
typedef partials_return_type_t<T_y, T_loc, T_scale, T_shape>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using

@@ -21,8 +21,9 @@ return_type_t<T_y, T_loc, T_scale, T_shape> pareto_type_2_lccdf(
typedef partials_return_type_t<T_y, T_loc, T_scale, T_shape>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using

@@ -22,8 +22,9 @@ return_type_t<T_y, T_loc, T_scale, T_shape> pareto_type_2_lcdf(
typedef partials_return_type_t<T_y, T_loc, T_scale, T_shape>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using

@@ -14,37 +14,37 @@ typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>::Index size_type;
* The type of a matrix holding <code>var</code>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using at line 11

@SteveBronder
Copy link
Collaborator Author

@rok-cesnovar thanks for the review! I think I cleaned up all the rest of the typedefs. I left the ones in the MPI code that are used in a macro because I was worried about touching those. But everywhere else should be good to go

@stan-buildbot
Copy link
Contributor

(stat_comp_benchmarks/benchmarks/gp_pois_regr/gp_pois_regr.stan, 1.01)
(stat_comp_benchmarks/benchmarks/low_dim_corr_gauss/low_dim_corr_gauss.stan, 0.97)
(stat_comp_benchmarks/benchmarks/irt_2pl/irt_2pl.stan, 1.0)
(stat_comp_benchmarks/benchmarks/pkpd/one_comp_mm_elim_abs.stan, 1.02)
(stat_comp_benchmarks/benchmarks/eight_schools/eight_schools.stan, 1.02)
(stat_comp_benchmarks/benchmarks/gp_regr/gp_regr.stan, 0.96)
(stat_comp_benchmarks/benchmarks/arK/arK.stan, 1.0)
(performance.compilation, 1.02)
(stat_comp_benchmarks/benchmarks/low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan, 1.0)
(stat_comp_benchmarks/benchmarks/low_dim_gauss_mix/low_dim_gauss_mix.stan, 1.0)
(stat_comp_benchmarks/benchmarks/sir/sir.stan, 1.05)
(stat_comp_benchmarks/benchmarks/pkpd/sim_one_comp_mm_elim_abs.stan, 1.0)
(stat_comp_benchmarks/benchmarks/garch/garch.stan, 0.99)
(stat_comp_benchmarks/benchmarks/gp_regr/gen_gp_data.stan, 0.97)
(stat_comp_benchmarks/benchmarks/arma/arma.stan, 0.92)
Result: 0.99587011727
Commit hash: 028ab67

Copy link
Member

@rok-cesnovar rok-cesnovar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Agreed on leaving the ones you are not sure about. Thanks!

@rok-cesnovar rok-cesnovar merged commit d4e9332 into develop Sep 9, 2019
@rok-cesnovar rok-cesnovar mentioned this pull request Sep 9, 2019
5 tasks
@serban-nicusor-toptal serban-nicusor-toptal added this to the 3.0.0 milestone Oct 18, 2019
@SteveBronder SteveBronder deleted the refactor/clang-tidy-cleanup branch December 30, 2019 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants